//
//  LPChooseTitleShowTitleView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/8/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPChooseTitleShowTitleView.h"

@interface LPChooseTitleShowTitleView ()
/**  标题  */
@property (strong, nonatomic) UILabel  *headLine;
/**  显示文字  */
@property (strong, nonatomic) UILabel  *showLabel;
/**  点击图片  */
@property (strong, nonatomic) UIImageView  *imageView;
/**  下划线  */
@property (strong, nonatomic) UIView  *underLabel;
/**    */
@property (assign, nonatomic) CGFloat  titleWidth;


@end
@implementation LPChooseTitleShowTitleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.headLine];
        [self addSubview:self.showLabel];
        [self addSubview:self.imageView];
        [self addSubview:self.underLabel];
        
        CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:@"志愿者活动类型" font:15 * [UIScreen zj_textFontScale] height:12 * [UIScreen zj_screenHScale]].width;
        self.titleWidth = width;
        
        self.headLine.sd_layout
        .topSpaceToView(self, 3 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .widthIs(width)
        .heightIs(12 * [UIScreen zj_screenHScale]);
        self.headLine.text = @"志愿者活动类型";
        
        self.showLabel.sd_layout
        .topSpaceToView(self, 3 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.headLine, 20 * [UIScreen zj_screenWScale])
        .widthIs(90)
        .heightIs(12 * [UIScreen zj_screenHScale]);
        
        self.imageView.sd_layout
        .topSpaceToView(self, 3 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.showLabel, 5 * [UIScreen zj_screenWScale])
        .widthIs(12 * [UIScreen zj_screenHScale])
        .heightIs(12 * [UIScreen zj_screenHScale]);
        
        self.underLabel.sd_layout
        .bottomEqualToView(self)
        .leftEqualToView(self.showLabel)
        .widthIs(3)
        .heightIs(1);
        
    }
    return self;
}


- (void)setShowString:(NSString *)showString{
    _showString = showString;
    CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:showString font:15 * [UIScreen zj_textFontScale] height:12 * [UIScreen zj_screenHScale]].width;
    CGFloat width1 = [UIScreen zj_screenWith] - self.titleWidth - 20 * [UIScreen zj_screenWScale] - 12 * [UIScreen zj_screenHScale] - 23 * [UIScreen zj_screenWScale];
    
    CGFloat titlewidth = 0.0;
    if (width > width1) {
        titlewidth = width1;
    }else{
        titlewidth = width;
    }
    
    self.showLabel.text = showString;
    self.showLabel.sd_layout.widthIs(titlewidth);
    [self.showLabel updateLayout];
    
    
    self.underLabel.sd_layout.widthIs(titlewidth);
    [self.underLabel updateLayout];
    
    
}

- (void)tapimage{

    if (self.delegate) {
        [self.delegate LPChooseTitleShowTitleView_click];
    }
}

- (UILabel *)headLine{
    if (!_headLine) {
        _headLine = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label;
        });
    }
    return _headLine;
}


- (UILabel *)showLabel{
    if (!_showLabel) {
        _showLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapimage)];
            [label addGestureRecognizer:tap];
            label;
        });
    }
    return _showLabel;
}



- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [UIImageView new];
        _imageView.contentMode = UIViewContentModeCenter;
        _imageView.image = [UIImage imageNamed:@"sign_select_more"];
        _imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapimage)];
        [_imageView addGestureRecognizer:tap];
    }
    return _imageView;
}

- (UIView *)underLabel{
    if (!_underLabel) {
        _underLabel = [UIView new];
        _underLabel.backgroundColor = [UIColor lightGrayColor];
    }
    return _underLabel;
}

@end
